//
//  IGUser.m
//  jingdongfang
//
//  Created by BOE on 2017/8/9.
//  Copyright © 2017年 ZhiYu Hao. All rights reserved.
//

#import "IGUser.h"
#import "IGUserDefaults.h"

@implementation IGUser

+ (IGUserDefaults *)userDefaults {
    return [IGUserDefaults shareIGUserDefaults];
}

+ (void)loginSuccessWithModel:(IGUserInfo *)model
                   completion:(void (^)())completion
{
    [self saveUserInfo:model];

    [IGUser userDefaults].loginStatus = YES;
    if (completion) {
        completion();
    }
}

+ (void)saveUserInfo:(IGUserInfo *)model{
    IGUserDefaults *userDefaults = [IGUser userDefaults];
    userDefaults.uid               = model.uid;
    userDefaults.nike              = model.nike;
    userDefaults.image             = model.image;
    userDefaults.collectionNums    = model.collectionNums;
    userDefaults.followNums        = model.followNums;
    userDefaults.worksNums         = model.worksNums;
    userDefaults.content           = model.content;
    userDefaults.uToken            = model.uToken;
    userDefaults.tel               = model.tel;
    userDefaults.type              = model.type;
    userDefaults.authens           = model.authens;
    userDefaults.focusNums         = model.focusNums;
    userDefaults.totalEquNums      = model.totalEquNums;
    userDefaults.albumNums         = model.albumNums;
    userDefaults.unReadTotal       = model.unReadTotal;
    userDefaults.authensContent    = model.authen.content;
    userDefaults.hasLabelSetting    =model.hasLabelSetting;
}

+ (void)saveNike:(NSString *)nike {
    [IGUser userDefaults].nike              = nike;
}

+ (void)saveImage:(NSString *)image {
    [IGUser userDefaults].image             = image;
}

+ (void)saveAuthens:(NSString *)authens {
    [IGUser userDefaults].authens           = authens;
}

+ (void)saveTel:(NSString *)tel {
    [IGUser userDefaults].tel               = tel;
}

+ (BOOL)isLogin{
    return [IGUser userDefaults].loginStatus;
}

+ (void)logout {
    [JPUSHService deleteAlias:nil seq:1];
    [IGUser userDefaults].loginStatus = NO;
    [IGUser userDefaults].uToken = nil;
    [IGUser userDefaults].uid = nil;
}

+ (NSString *)getUid {
    NSString *uId = [IGUser userDefaults].uid;
    return uId == nil ? @"":uId;
}

+ (NSString *)getTel {
    NSString *tel = [IGUser userDefaults].tel;
    return tel == nil ? @"":tel;
}

+ (NSString *)getuToken {
    NSString *uToken = [IGUser userDefaults].uToken;
    return uToken == nil ? @"":uToken;
}

+ (NSString *)getNike {
    return [IGUser userDefaults].nike;
}

+ (NSString *)getCollectionNums {
    return [IGUser userDefaults].collectionNums;
}

+ (NSString *)getContent {
    return [IGUser userDefaults].content;
}

+ (NSString *)getImage {
    return [IGUser userDefaults].image;
}

+ (NSString *)getFollowNums {
    return [IGUser userDefaults].followNums;
}

+ (NSString *)getAuthens {
    return [IGUser userDefaults].authens;
}

+ (NSString *)getAuthensContent {
    return [IGUser userDefaults].authensContent;
}

+ (NSString *)getType {
    return [IGUser userDefaults].type;
}
+ (NSString *)getHasLabelSetting {
    return [IGUser userDefaults].hasLabelSetting;
}

+ (IGUserInfo *)getUserInfo {
    IGUserInfo *userInfo = [[IGUserInfo alloc] init];
    IGUserDefaults *userDefaults = [IGUser userDefaults];
    
    userInfo.uid = userDefaults.uid;
    userInfo.nike = userDefaults.nike;
    userInfo.image = userDefaults.image;
    userInfo.collectionNums = userDefaults.collectionNums;
    userInfo.followNums = userDefaults.followNums;
    userInfo.worksNums = userDefaults.worksNums;
    userInfo.content = userDefaults.content;
    userInfo.tel = userDefaults.tel;
    userInfo.type = userDefaults.type;
    userInfo.authens = userDefaults.authens;
    userInfo.focusNums = userDefaults.focusNums;
    userInfo.albumNums = userDefaults.albumNums;
    userInfo.totalEquNums = userDefaults.totalEquNums;
    userInfo.unReadTotal = userDefaults.unReadTotal;
    userInfo.hasLabelSetting=userDefaults.hasLabelSetting;
    
    return userInfo;
}

@end
